# 初始化生产各个环境的user
from django.contrib.auth import authenticate, login
from django.contrib.auth import logout
from django.http import HttpResponseRedirect
from django.shortcuts import render

'''
登入登出相关
'''


# 登录
def do_login(request):
    username = request.POST.get('username', '')
    password = request.POST.get('password', '')

    user = authenticate(request, username=username, password=password)
    if user is not None:
        login(request, user)
        return HttpResponseRedirect('/master')
    else:
        return render(request, 'master/login.html', {
            'username': username,
            'password': password,
        })


# 登出
def login_out(request):
    """注销用户"""
    logout(request)
    return render(request, 'master/login.html')
